using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_coverletters : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "Database2000"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                ShowCoverLetter();
            }
        }
    }
    void ShowCoverLetter()
    {
        SqlServerProvider cls = new SqlServerProvider(connectionString);
        cls.CommandText = "select LetterID,Subject, " +
        "Convert(char(10), CreateDate,103) as CreateDate ,"
        +"Convert(char(10), UpdateDate,103) as UpdateDate " +
        " from tblJSCoverLetters " +
        " where UserID='" + Convert.ToString(
        Session.Contents["jsuserid"])
        + "'";
        DataTable dataTable = cls.GetDataTable();
        GridView1.DataSource = dataTable;
        GridView1.DataBind();
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("coverletter.aspx");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        DeleteCoverLetter();
        ShowCoverLetter();
    }
    void DeleteCoverLetter()
    {
        string letterID = "";
        foreach (GridViewRow item in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)item.Cells[0].FindControl("chkCoverLetterID");
            if (checkBox.Checked)
                letterID += item.Cells[0].Text + ",";
        }
        if (letterID != "")
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "delete  from tblJSCoverLetters " +
            " where UserID='" + Convert.ToString(
            Session.Contents["jsuserid"])
            + "' and LetterID in('" +
            letterID.Replace(",", "','") + "')";
            cls.ExecuteNonQuery();
        }
    }
}
